package org.lonetree.tc.webapp.actions;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.lonetree.tc.core.dao.BookDAO;
import org.lonetree.tc.core.dao.DAOFactory;

public class DeleteSource extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try{
			
				if (request.getParameter("source_id")!= null)
				{
					int id=Integer.parseInt(request.getParameter("source_id"));
					Connection connection=null;
					try{
			            Class.forName("com.mysql.jdbc.Driver");
			            connection =DriverManager.getConnection
			                    ("jdbc:mysql://localhost:3306/tc","tc","textbookcrossroads");
			            String query="delete from sources where id='"+id+"'";
			            Statement statement=connection.createStatement();
			            statement.executeUpdate(query);
			            connection.close();
			            return mapping.findForward("success");
			            }
			        catch (Exception e){
			            return mapping.findForward("failure");
			        	}        
				}	
			return mapping.findForward("failure");	
		}
		catch (Exception e)
		{
			return mapping.findForward("failure");
		}
	}

}
